/**
 * Created by cjd on 2016/6/14.
 */
angular.module("app").controller("group.base.Ctrl", ["$scope", "groupBase", '$state', "$stateParams", function ($scope, groupBase, $state, $stateParams) {
    if($stateParams.id){
        groupBase.getDetail({}, {id: $stateParams.id}, function (data) {
            $scope.baseDetail = data.data
        });
    }else{
        groupBase.getList({}, {}, function (data) {
            $scope.baseList = data.data
        });
    }
    $scope.sendComment = function (status) {
        if(status == 2){
            var val = $('.add-score').val(), numberReg = /^\d+$/
            if(val < 1 || val > 10 || !numberReg.test(val)){
                alert('请输入有效分数,且范围为1-10分')
                return
            }
            groupBase.sendComment({}, {id: $stateParams.id, score: val}, function (data) {
                if(data.statusCode == 0){
                    alert(data.statusMessage)
                    $state.go('home.group.base')
                }else{
                    alert(data.statusMessage)
                }
            })
        }else{
            if($('.add-remark').val() == ''){
                alert('请填写您的意见')
                return
            }
            groupBase.sendComment({}, {id: $stateParams.id, status: status, remark: $('.add-remark').val()}, function (data) {
                if(data.statusCode == 0){
                    alert(data.statusMessage)
                    $state.go('home.group.base')
                }else{
                    alert(data.statusMessage)
                }
            })
        }
    }
}]);